require("../../assets/css/basic.css");
require("../../assets/css/normalize.css");
require("../../assets/css/reset.css");
require("./mine.less");
require("../../assets/css/tabbar.less");

//引入字体图标
require("../../assets/font3/iconfont.css");
require("../../assets/font3/iconfont.js");
require("../../assets/fonts/iconfont.css");
require("../../assets/font1/iconfont.css");

// 引入模块
const dom = require("../../utils/dom.js");
const axios = require("axios");
require("weui");

document.addEventListener("DOMContentLoaded", function () {
	//渲染底部导航栏
	dom.tabbar("mine");
	//退出登录交互
	dom.get(".logoutbtn").addEventListener("click", function () {
		weui.confirm("是否确认退出登录?", function () {
			localStorage.clear();
			location.href = "login.html";
		});
	});

	// baseURL便于为axios实例的方法传递相对 URL
	axios.defaults.baseURL = "http://fitness.h5.itsource.cn:3701";
	let token = localStorage.getItem("token");
	axios.defaults.headers.common["Authorization"] = "Bearer " + token;
	// 渲染个人信息
	axios.get("/api/user/info").then(function (res) {
		let data = res.data.data;
		dom.get(".profile").src = axios.defaults.baseURL + data.imgUrl;
		dom.get(".username").textContent = data.nickName;
		dom.get(".signature").textContent = data.sign;
	});
	//渲染运动数据
	axios.get("/api/exercise").then(function (res) {
		let data = res.data.data;
		//渲染排名
		dom.get(".sumDuration").textContent = data.sum7Duration;
		//渲染徽章
		dom.get(".sumCalorie").textContent = data.sum7Calorie;
	});
	//渲染徽章数据
});
